<template>
  <div class="musicList">
    <div class="musicTop">
      <div class="title">发现好歌单</div>
      <div class="more">查看更多</div>
    </div>
    <div class="musicContent">
      <van-swipe :loop="false" :width="150" :show-indicators="false" class="my-swipe">
          <van-swipe-item v-for="item in state.musicList" :key="item.id">
          <router-link :to="{path:'/itemMusic', query:{id:item.id}}">
          <img :src="item.picUrl"  alt="">
          <span class="playCount"> 
               <svg class="icon" aria-hidden="true">
                   <use xlink:href="#icon-play"></use>
               </svg>{{ changeCount(item.playCount) }}
          </span>
          <span class="name">{{ item.name }}</span>
        </router-link>
          </van-swipe-item>
      
      </van-swipe>
    </div>
  </div>
</template>
<script>
import { reactive, onMounted } from "vue"
import { getMusicList } from '@/request/api/home'
export default {
  setup() {
    const state = reactive({
      musicList: []
    })
    function changeCount(count){
      if(count>10000){
        return (count/10000).toFixed(1)+'w'
      }
    }
    onMounted(async ()=>{
     const {data:res} = await getMusicList()
      state.musicList = res.result
     
    })
    return { state,changeCount }
  }
}
</script>
<style lang="scss" scoped>
.musicList {
  width: 100%;
  height: 5rem;
  padding: 0.2rem;
  .musicTop {
    width: 100%;
    height: 0.6rem;
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.2rem;

    .title {
      font-size: 0.4rem;
      font-weight: 800;
    }

    .more {
      border: 1px solid #ccc;
      text-align: center;
      line-height: 0.6rem;
      border-radius: 0.6rem;
      padding: 0 0.2rem;
    }
  }
  .musicContent{
    width: 100%;
    height: 4rem;
    .my-swipe{
     
      img {
        width: 100%;
        height: 100%;
        border-radius: 25px;
      }
      .van-swipe-item {
        padding-right: .3rem;
        position: relative;
      .playCount{
        display: flex;
        align-items: center;
        position: absolute;
        top: 0;
        right: .5rem;
        font-size: .28rem;
        color: aliceblue;
        line-height:.58rem ;
        z-index: 999;
        .icon{
          width: .28rem;
          color: #000;
        }
      }
      .name{
        font-size:.24rem;
      }}
    }
  }
}
</style>
